<?php
require_once APP . '/application/controllers/FrontAction.php';
require_once APP . '/application/models/Article.php';

/**
 * 组织架构
 */
class ZzjgController extends FrontAction
{
    
	public function init()
	{
		$this->view->typename = "People";
	}
    /**
     * 首页
     *
     */
    public function indexAction()
    {
    	// empty
    }
    

    /**
     * 列表页面
     *
     */
    public function listAction()
    {
    	$id = (int)$_REQUEST['id'];
    	 
    	$nowp = intval($this->getParam("nowp", 1));
    	 
    	// 读取文章列表
    	$obj_article = new Article($this->db);
    	$result = $obj_article->listArticle($id, $nowp, 15);
    	
    	// 读取特殊列表    	
    	$arr_zzjg = $this->view->types['zzjg'];
    	$ids_zzjg = implode(",", array_keys($arr_zzjg));
    	
    	$arr_types = $this->db->fetchAll("select aid,title,cid from article where cid in({$ids_zzjg}) order by seq desc,aid desc");
    	$arr_type_v = array();
    	foreach ($arr_types as $v){
    		$arr_type_v[$v['cid']][] = $v;
    	}
    	$this->view->arr_type = $arr_type_v;
    	
    	if (isset($arr_type_v[$id]) && count($arr_type_v[$id]) > 0){
			$_REQUEST['id'] = $arr_type_v[$id][0]['aid'];
			return $this->showAction();
    	}
    	
    	
    	$this->view->list = $result['list'];
    	$this->view->page = $result['page'];
    	$this->view->pagenum = Util::pageNumStyle($result['page']);

    	$this->view->typeid = $id;
    	$this->view->cname = $this->getParam("c");
    	$this->view->htitle = $this->view->typename;
    	
    	$this->render("list");
    }
    
    /**
     * 显示页面
     *
     */
    public function showAction()
    {
    	$id = (int)$_REQUEST['id'];
    	
    	$nowp = intval($this->getParam("nowp", 1));
    	
    	// 读取文章列表
    	$obj_article = new Article($this->db);
    	$arr_articleinfo = $obj_article->show($id);
    	$cid = $arr_articleinfo['cid'];
    	
    	// 读取特殊列表    	
    	$arr_zzjg = $this->view->types['zzjg'];
    	$ids_zzjg = implode(",", array_keys($arr_zzjg));
    	
    	$arr_types = $this->db->fetchAll("select aid,title,cid from article where cid in({$ids_zzjg}) order by seq desc,aid desc");
    	$arr_type_v = array();
    	foreach ($arr_types as $v){
    		$arr_type_v[$v['cid']][] = $v;
    	}
    	$this->view->arr_type = $arr_type_v;
    	
    	$this->view->typeid = $cid;
    	$this->view->cname = $this->getParam("c");
    	$this->view->content = $arr_articleinfo;
    	$this->view->htitle = htmlspecialchars($arr_articleinfo['title']);

    	$this->render("show");
    }
}
